package com.itcoon.transform4j.demo.web.controller;

import com.itcoon.common.web.core.response.ApiResponse;
import com.itcoon.transform4j.demo.web.vo.BookVIO;
import com.itcoon.transform.starter.Transformer;
import com.itcoon.transform4j.demo.domain.Author;
import com.itcoon.transform4j.demo.domain.Book;
import com.itcoon.transform4j.demo.domain.Company;
import com.itcoon.transform4j.demo.web.vo.BookVCO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "03_assemble_基础篇", description = "嵌套对象编集测试, 编集后属性提升, mapValue的作用")
@RestController
@RequestMapping("/api")
public class BaseCasedeAssembleController {

    @ApiOperation(value = "获取书的信息(目标对象为接口定义)")
    @GetMapping("/books")
    public ApiResponse<BookVIO> getBook(){
        Book book = new Book();
        book.setId(1L);
        book.setName("西游记");

        Author author = new Author();
        author.setName("吴承恩");

        Company company = new Company();
        company.setName("江南书院");
        company.setLocation("扬州");
        author.setCompany(company);
        book.setAuthor(author);

        BookVIO bookVIO = Transformer.to(BookVIO.class).apply(book).done();
        return ApiResponse.createSuccess(bookVIO);
    }

    @ApiOperation(value = "获取书的信息(目标对象为类定义)")
    @GetMapping("/books2")
    public ApiResponse<BookVCO> getBook2(){
        Book book = new Book();
        book.setId(1L);
        book.setName("西游记");

        Author author = new Author();
        author.setName("吴承恩");

        Company company = new Company();
        company.setName("江南书院");
        company.setLocation("扬州");
        author.setCompany(company);
        book.setAuthor(author);

        BookVCO bookVCO = Transformer.to(BookVCO.class).apply(book).done();
        return ApiResponse.createSuccess(bookVCO);
    }


    @ApiOperation("获取书的信息(目标对象为接口定义， 嵌套对象为空)")
    @GetMapping("/books3")
    public ApiResponse<BookVIO> getBook3(){
        Book book = new Book();
        book.setId(1L);
        book.setName("西游记");

        Author author = new Author();
        author.setName("吴承恩");

        book.setAuthor(author);

        BookVIO bookVIO = Transformer.to(BookVIO.class).apply(book).done();
        return ApiResponse.createSuccess(bookVIO);
    }

    @ApiOperation("获取书的信息(目标对象为类定义， 嵌套对象为空)")
    @GetMapping("/books4")
    public ApiResponse<BookVCO> getBook4(){
        Book book = new Book();
        book.setId(1L);
        book.setName("西游记");

        Author author = new Author();
        author.setName("吴承恩");

        book.setAuthor(author);

        BookVCO bookVCO = Transformer.to(BookVCO.class).apply(book).done();
        return ApiResponse.createSuccess(bookVCO);
    }
}
